using UnityEngine;
using System.Collections;

public class DropShadow : MonoBehaviour {

    private Color color;
    private bool isValidPlacement;

    public bool IsValidPlacement
    {
        get { return isValidPlacement; }
    }

	// Use this for initialization
	void Start () {

        color = new Color(0.0f, 1.0f, 0.0f, 0.5f);
	}
	
	// Update is called once per frame
	void Update () {
        gameObject.renderer.material.color = color;
	}

    void OnTriggerStay(Collider other)
    {
        // If we collided with a carryable, or we collided with a non-floor non-hazard object, BAD
        if (other.gameObject.GetComponent<Carryable>() != null)
        {
            color = new Color(1.0f, 0.0f, 0.0f, 0.5f);
            isValidPlacement = false;
            //Debug.Log("INVALID PLACEMENT: Hands full");
        }
        //else if (other.gameObject.GetComponent<Hazard>() != null || other.gameObject.tag == "Floor")
        //{
        //    color = new Color(0.0f, 1.0f, 0.0f, 0.5f);
        //    isValidPlacement = true;
        //    Debug.Log("Valid placement: " + other.gameObject.name + " (" + other.gameObject.tag + ")");
        //}
        //else
        else if (other.gameObject.GetComponent<Hazard>() == null && other.gameObject.tag != "Floor")
        {
            color = new Color(1.0f, 0.0f, 0.0f, 0.5f);
            isValidPlacement = false;
            //Debug.Log("ELSE INVALID PLACEMENT: " + other.gameObject.name + " (" + other.gameObject.tag + ")");

        }
    }

    void OnTriggerExit(Collider other)
    {
        // If we just left an invalid placement, then we are valid?
        // If we collided with a carryable, or we collided with a non-floor non-hazard object, BAD
        if (other.gameObject.GetComponent<Carryable>() != null)
        {
            color = new Color(0.0f, 1.0f, 0.0f, 0.5f);
            isValidPlacement = true;
            //Debug.Log("left crate");
        }
        else if (other.gameObject.GetComponent<Hazard>() == null && other.gameObject.tag != "Floor")
        {
            color = new Color(0.0f, 1.0f, 0.0f, 0.5f);
            isValidPlacement = true;
            //Debug.Log("left else");

        }        
    }
}
